//
//  LoginUser.m
//  MyChat
//
//  Created by Ansen on 15-2-1.
//  Copyright (c) 2015年 Ansen. All rights reserved.
//

#define kXMPPUserNameKey    @"xmppUserName"
#define kXMPPPasswordKey    @"xmppPassword"
#define kXMPPHostNameKey    @"xmppHostName"

#import "LoginUser.h"
#import "NSString+Helper.h"

@implementation LoginUser
single_implementation(LoginUser)

-(NSString *)loadStringFromDefaultsWithKey:(NSString *)key
{
    NSString *str = [UserDefault stringForKey:key];
    return str ? str : @"";
}

-(void)setUserName:(NSString *)userName
{
    [userName saveToNSDefaultsWithKey:kXMPPUserNameKey];
}

-(void)setPassword:(NSString *)password
{
    [password saveToNSDefaultsWithKey:kXMPPPasswordKey];
}

-(void)setHostName:(NSString *)hostName
{
    [hostName saveToNSDefaultsWithKey:kXMPPHostNameKey];
}

-(NSString *)userName
{
    return [self loadStringFromDefaultsWithKey:kXMPPUserNameKey];
}

-(NSString *)password
{
    return [self loadStringFromDefaultsWithKey:kXMPPPasswordKey];
}

-(NSString *)hostName
{
    return [self loadStringFromDefaultsWithKey:kXMPPHostNameKey];
}

-(NSString *)myJIDName
{
    return [NSString stringWithFormat:@"%@@%@",self.userName,self.hostName];
}

-(XMPPJID *)myJID
{
    return [XMPPJID jidWithString:self.myJIDName];
}

@end
